<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="utf-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path;
%>

<c:set var="ctx" value="<%=basePath%>"/>
<%--<%@include file="" %>--%>
<html xmlns:th="http://www.thymeleaf.org" lang="en" class="no-js">

<head>
    <meta charset="utf-8"/>
    <meta name="author" content=""/>
    <meta name="keywords" content=""/>
    <meta name="viewport" content="width=device-width,initial-scale=1"/>
    <title>order</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <script type="text/javascript" src="${ctx}/static/js/jquery-1.10.2.min.js"></script>
    <%--<script type="text/javascript" src="../static/js/jquery-1.10.2.min.js"></script>--%>


</head>
<body style="background-image: none;" id="body">
<div id="content">
<%--<form id="payForm" method="post" action="http://localhost:8080/api/order/pay">--%>
<form id="payForm" method="post" >
    订单号：<input type="text" name="orderID" id="orderID"/><br>
    支付方式： <input type="text" name="payType" id="payType"/><br>
    客户端类型： <input type="text" name="clientType" id="clientType"/><br>
    <input type="hidden" name="orderSource" id="orderSource" value="1"/><br>
    <input type="submit" value="支付" onclick="pay()" /><br>
</form>
</div>
<script>

    function pay() {
        var payType = $("#payType").val();
        $.ajax({
            type: "post",
            url: "${ctx}/api/pay/pay",
            async: false,
            dataType: "text",
            data: {
                orderID: $("#orderID").val(),
                payType: $("#payType").val(),
                orderSource: $("#orderSource").val(),
                clientType: $("#clientType").val()
            },
            success: function (data) {
                console.log(data);
                var obj = JSON.parse(data);
                if(obj.code == 0 ){
                    if(payType == 2){
                        document.write(obj.result);
                    }else{
                        //document.write(obj.result);
                        document.write("<img src = \"data:image/jpeg;base64,"+obj.result+"\"/>");
                    }
                }else {
                    document.write(obj.msg);
                }
            }
        });
    }


</script>

</body>
</html>